from typing import List

import pytest

from db_study.db_util import DBUtil
from apis_study.bank_apis import user_login
from apis_study.cookie_study import cookie_login, cookie_logout
from apis_study.token_study import token_login, token_logout


@pytest.fixture(scope="session", autouse=False)
def cookie_login_fixture():
    cookie_login()
    print("登录了")
    yield
    cookie_logout()
    print("执行完成，已成功退出")


@pytest.fixture(scope="session", autouse=False)
def token_login_fixture():
    token = token_login()
    print("登录了")
    yield token
    token_logout()
    print("执行完成，已成功退出")

@pytest.fixture(scope='session',autouse=False)
def get_token():
    resp = user_login()
    admin_token = resp.json()['token']
    print('执行fixture函数')
    yield admin_token# yield的下一行表示后置处理
    # return buyer_token 这种返回也行，但是他不支持后置处理
    print('用例执行完成了，退出登录')

@pytest.fixture(scope='session',autouse=False)
def db_init():
    db_util = DBUtil(host='192.168.239.129', user='root', password='123456', database='kejiyinhangyewuguanli')
    yield db_util
    db_util.close()